public class Demo {
    public static void main(String[] args) throws InterruptedException {
        //final boolean isFinished = false;//如果lamada在main函数内部，必须加上final修饰，不能让该值改变
        Thread t = new Thread(() -> {
            while (!Thread.currentThread().isInterrupted()) {
                System.out.println("hello t");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    //e.printStackTrace();//由于interrupt()函数把sleep唤醒，导致sleep捕捉异常从而报错
                    //并且sleep会继续把isInterrupt()设为false ，这样可以给程序员更多的选择
                    break;
                }
            }
        });

        t.start();
        Thread.sleep(10000);
        t.interrupt();
    }
}
